import { request } from '@/utils/T';
import { processAPI } from '@/constants/EnumAPI';
const { postJSON, get } = request;

/**
 * 保存表单配置
 * @param name
 * @param config
 * @returns {Promise}
 * @constructor
 */
export const SaveFormConfig = (name = '', config = {}) => postJSON(processAPI('form/save'), { name, config });

/**
 * 获取所有表单配置
 * @returns {Promise}
 * @constructor
 */
export const GetFormConfigList = () => get(processAPI('form/getAll'));

/**
 * 获取表单配置
 * @param id
 * @returns {Promise}
 * @constructor
 */
export const GetFormConfig = (id = '') => get(processAPI('form/getById'), { id });

/**
 * 获取流程列表
 * @returns {Promise}
 * @constructor
 */
// export const GetFlowList = () => get(window.ENV.jFlowApiDomain + '/base/engineServer/flowDesign/getFlowList');
export const GetFlowList = () => get(processAPI('/form/getRelated'));

/**
 * 关联表单
 * @param flowNo
 * @param formId
 * @returns {Promise}
 * @constructor
 */
export const RelationshipForm = (flowNo = '', formId = '') => postJSON(processAPI('/form/related'), { flowNo, formId });

/**
 * 创建表单数据表
 * @param params
 * @param params.formId
 * @param params.columns
 * @returns {Promise}
 * @constructor
 */
export const CreateFormTable = (params = { formId: '', columns: [] }) => postJSON(processAPI('form/createTable'), params);

/**
 * 保存表单数据
 * @param params
 * @param params.workId
 * @param params.formId
 * @param params.data
 * @returns {Promise}
 * @constructor
 */
export const SaveFormData = (params = { workId: '', formId: '', data: {}}) => postJSON(processAPI('form/saveData'), params);

/**
 * 获取表单数据
 * @param workId
 * @param flowNo
 * @returns {Promise}
 * @constructor
 */
export const GetFormData = (workId = '', flowNo = '') => get(processAPI('form/getData'), { workId, flowNo });

/**
 * 启动流程
 * @param params
 * @param params.userNo
 * @param params.flowNo
 * @param params.sysNo
 * @param params.toEmps
 * @returns {Promise}
 * @constructor
 */
export const StartFlow = (params = { userNo: 'test1', flowNo: '', sysNo: '1001', toEmps: 'test2' }) => {
  return postJSON(window.ENV.jFlowApiDomain + '/base/engineServer/flowEngine/startFlow', params);
};

/**
 * 获取待办列表
 * @param params
 * @param params.userNo
 * @param params.sysNo
 * @param params.page
 * @param params.size
 * @returns {Promise}
 * @constructor
 */
export const GetTodoList = (params = { userNo: 'test2', sysNo: '1001', page: 1, size: 10 }) => {
  return postJSON(window.ENV.jFlowApiDomain + '/base/engineServer/flowList/todoList', params);
};

/**
 * 发送流程
 * @param params
 * @param params.userNo
 * @param params.sysNo
 * @param params.toEmps
 * @param params.workId
 * @returns {Promise}
 * @constructor
 */
export const SendFlow = (params = { userNo: 'test2', sysNo: '1001', toEmps: 'test2', workId: '' }) => postJSON(window.ENV.jFlowApiDomain + '/base/engineServer/flowEngine/sendWork', params);

/**
 * 获取已完成任务列表
 * @param params
 * @param params.userNo
 * @param params.sysNo
 * @param params.page
 * @param params.size
 * @returns {Promise}
 * @constructor
 */
export const GetCompleteList = (params = { userNo: 'test2', sysNo: '1001', page: 1, size: 10 }) => {
  return postJSON(window.ENV.jFlowApiDomain + '/base/engineServer/flowList/completeList', params);
};
